﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using ESRI.ArcGIS.Controls;
using ESRI.ArcGIS.Carto;

namespace DIWAGIS.ApplicationLayer.BanDo
{
    public partial class frmChonLopDuLieuChinhSua : Form
    {
        private IMapControl4 m_mapControl;
        public IMapControl4 mapControl
        {
            get { return m_mapControl; }
            set { m_mapControl = value; }
        }

        private IList<string> m_lstSourceType;// = new List<string>();
        public IList<string> lstSourceType
        {
            get { return m_lstSourceType; }
            set { m_lstSourceType = value; }
        }

        private string m_SelectedLayer;
        public string SelectedLayer
        {
            get { return m_SelectedLayer; }
            set { m_SelectedLayer = value; }
        }

        private string m_SelectedSourceType;
        public string SelectedSourceType
        {
            get { return m_SelectedSourceType; }
            set { m_SelectedSourceType = value; }
        }

        public frmChonLopDuLieuChinhSua()
        {
            InitializeComponent();
        }

        private void buttonChon_Click(object sender, EventArgs e)
        {
            try
            {
                if (listBoxLopDuLieu.SelectedIndex >= 0)
                {
                    m_SelectedLayer = listBoxLopDuLieu.SelectedItem.ToString();
                    SelectedSourceType = listBoxNguon.SelectedItem.ToString();
                    this.Close();
                }
            }
            catch (Exception ex)
            {
                Class.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

        private void buttonHuyBo_Click(object sender, EventArgs e)
        {
            try
            {
                this.Close();
            }
            catch (Exception ex)
            {
                Class.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

        private void frmChonLopDuLieuChinhSua_Load(object sender, EventArgs e)
        {
            try
            {
                for (int i = 0; i < m_lstSourceType.Count; i++)
                {
                    listBoxNguon.Items.Add(m_lstSourceType[i]);
                }
            }
            catch (Exception ex)
            {
                Class.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

        private void listBoxNguon_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                listBoxLopDuLieu.Items.Clear();
                string selectedSourceType = listBoxNguon.SelectedItem.ToString();
                if (selectedSourceType != string.Empty)
                {
                    IList<ILayer> lstLayer = Class.WorkingWithLayer.GetAllLayer(m_mapControl);
                    for (int i = 0; i < lstLayer.Count; i++)
                    {
                        if (((IFeatureLayer)lstLayer[i]).DataSourceType == selectedSourceType)
                        {
                            listBoxLopDuLieu.Items.Add(lstLayer[i].Name);
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                Class.clsStaticFunctions.ThongBaoLoi(ex);
            }
        }

       
    }
}
